<template>
	<view  class="w100 bg_white pB100ux">
		<view class="p10">
				<view class="user-message" >
					企业法人：{{companyinfodata.corporation}}
				</view>
		
				<view class="user-message" >
					企业地址：{{companyinfodata.address}}
				</view> 
				<view class="user-message" >
					企业名称：{{companyinfodata.name}}
				</view>		
				<view class="user-message" >
					信用代码：{{companyinfodata.code}}
				</view>
				<view class="user-message" >
					企业电话：{{companyinfodata.company_mobile}}
				</view>
				<view class="user-message" v-if="userForm.roleid!=2&&userForm.deptid!=0">
					所在部门：{{userForm.dept_name?userForm.dept_name:userForm.role_name}}
					<span  class='mL10 p2 pL5 pR5 borderr8 overflow bg_blue col_white f14' @click="choosecomnter2">退出部门</span>
				</view>
				<view class="user-message" v-if='userForm.company_name'>
					任职状态：{{userForm.company_name?userForm.role_name:'访客'}}
					<span v-if="userForm.roleid!=2" class='mL10 p2 pL5 pR5 borderr8 overflow bg_blue col_white f14' @click="choosecomnter">退出公司</span>
				</view>	
				<view class="user-message" >
					公司积分：{{companyinfodata.frequency}}
				</view>
				<view class="user-message2 " v-if="userForm.roleid==2">
					营业执照正面：
					<view class="user-imgshow" @click="previewImg(companyinfodata.imgurl)">
						<image :src="companyinfodata.imgurl?companyinfodata.imgurl:noimg" :onerror="noimg" style="height:100upx !important;" mode="widthFix"></image>
					</view>
				</view>
				
				<view class="user-message2 " v-if="userForm.roleid==2">
					授权书：
					<view class="user-imgshow" @click="previewImg(companyinfodata.warrant)">
						<image :src="companyinfodata.warrant?companyinfodata.warrant:noimg" :onerror="noimg"  style="height:100upx !important;" mode="widthFix"></image>
					</view>
				</view>
							
				<view class="uni-btn-v " v-if='userForm.roleid==2&&companyinfodata.status==2&&is_completepersonchanger'>
					<button form-type="submit" class="submit submitsm" @click="showyingye()" >重新认证</button>					
					<button form-type="submit" class="submit submitsm" @click="userexit()" >注销公司</button>
				</view>
				<view class="uni-btn-v " v-if='userForm.roleid==2&&companyinfodata.status==2&&is_completepersonchanger==false'>
					<button form-type="submit" class="submit submitsm" @click="gouseridcard()">实名认证</button>					
				</view>
		</view>
		<!-- 分享弹窗 -->
		<view mode="top-right" class="scan-box" v-if="visible">
			<view class="scan-item">
				<view class="scan-content">				
					<image src="../../static/slide-list/fork.png" class="scan-btn" @click="nologout"></image>
					<view class="title tCenter bold pT5">
						注销公司
					</view>
					<view class="w90 mauto input pT10">
						<view class="sm_titme">
							请问注销公司资料的原因：
						</view>
						<view class="pL10 pR10 pT5 pB5 borderall f14">
							<input style="font-size: 14px;" type="text" value="" v-model="logouttext" placeholder="注销原因" />
						</view>
						
					</view>
					<view class="scan-text ">
						<view class="w50 mauto flex flexcenter f16">
							<span class='bglin2 pT2 pB2 pL10 pR10 col_white borderr5' @click='nologout'>取消</span>
							<span class='bglin pT2 pB2 pL10 pR10 col_white borderr5' @click='addlogout'>确定</span>
						</view>
						
					</view>
				</view>
			</view>
		</view>
		<backnext></backnext>
		<!-- 底部导航 -->
		<footernav pagePath='user'></footernav>
		<!-- 加载动画 -->
		<loading v-if="!isloading()"></loading>
	</view>
</template>

<script>
import {userinfo,companyinfo,useredit,companylogout} from '../../common/api/user.js'; //引进requst方法
import {check,isNumber,isEmpty} from '@/common/graceChecker.js';
import {deptudeluser,applyexit} from '../../common/api/department.js'; //引进requst方法
export default {
	data() {
		return {
			is_completepersonchanger:false,
			sexpicker:['女','男'],
			sexindex:0,
			noimg: '../../static/img/noimg.jpg',
			chooseinput:true,
			visible:false,
			logouttext:'',
			userFormnew:"",
			userForm: {
				sex:0,
				roleid:0,
				company_name:"",
			},
			companyinfodata:{
				
			},
			
		};
	},
	methods: {
		gouseridcard(){
			uni.navigateTo({
			    url: '../shouquan/shengfen',
			});
		},
		nologout(){
			this.logouttext='';
			this.visible=false;
		},
		addlogout(){
			let that=this;
			if(!this.logouttext){
				uni.showToast({
				    icon: 'none',
				    title: '请输入注销原因',
				    duration: 2000
				});
				return
			}else{
				companylogout({remark:this.logouttext}).then(res=>{
					if(res.data.code === 200){
						
						uni.showModal({
						    title: '',
						    content: res.data.message,						
							
							buttonText: '确定',
							confirmText: "确定",
						    success: function (res) {
						        if (res.confirm) {
						            console.log('用户点击确定');
									that.visible=false;
									this.logouttext='';
									window.location.replace('/wap/#/pages/user/user')
						        } else if (res.cancel) {
						            console.log('用户点击取消');
						        }
						    }
						});
					}else{
						uni.showModal({
						    title: '',
						    content: res.data.message,						
							
							buttonText: '确定',
							confirmText: "确定",
						    success: function (res) {
						        if (res.confirm) {									
						        } else if (res.cancel) {
						            console.log('用户点击取消');
						        }
						    }
						});
					}
					
				})
			}
		},
		  previewImg(logourl) {
			  if(logourl){	  
				let _this = this;
				let imgsArray = [];
				imgsArray[0] = logourl
				uni.previewImage({
					current: 0,
					urls: imgsArray
				});
			}
		},
		choosecomnter2(){
				let _that = this
				uni.showModal({
				    title: '确认退出部门吗?',
				    // content: '这是一个模态弹窗',
				    success: function (res) {
				        if (res.confirm) {
							applyexit({uid:_that.userForm.id,type:'d'}).then(res=>{
								uni.showModal({
								    title: '',
								    content: res.data.message,
									showCancel:false,
								    success: function (res) {
								        if (res.confirm) {
								          window.location.replace('/wap/#/pages/user/user')
								        } else if (res.cancel) {
								            console.log('用户点击取消');
								        }
								    }
								});
							//	_that.userForm.company_name='';
							 // _that.backrefresh('123')
								
							})
				            // console.log('用户点击确定');
				        } else if (res.cancel) {
							/*bann*/
							return 
				            // console.log('用户点击取消');
				        }
				    }
				});
		},
		choosecomnter(){
				let _that = this
				uni.showModal({
				    title: '确认退出公司?',
				    // content: '这是一个模态弹窗',
				    success: function (res) {
				        if (res.confirm) {
							applyexit({uid:_that.userForm.id,type:'c'}).then(res=>{
								// uni.showToast({
								// 	icon: 'none',
								// 	title: res.data.message,
								// 	duration: 2000
								// });
								uni.showModal({
								    title: '',
								    content: res.data.message,
									showCancel:false,
								    success: function (res) {
								        if (res.confirm) {
								          window.location.replace('/wap/#/pages/user/user')
								        } else if (res.cancel) {
								            console.log('用户点击取消');
								        }
								    }
								});
							//	_that.userForm.company_name='';
							 // _that.backrefresh('123')
									
								
							})
				            // console.log('用户点击确定');
				        } else if (res.cancel) {
							/*bann*/
							return 
				            // console.log('用户点击取消');
				        }
				    }
				});
		},
		/*更换身份证号码--未开放*/
		showyingye(){			
			
			uni.navigateTo({
			    url: '../shouquan/yingye?type=chidcard&companyid='+this.companyinfodata.id
			});
			
		},
		userexit(){
			let that=this;
			if(this.userFormnew.member.member_cfrequency!=0){
					uni.showModal({
					    title: '',
					    content: '尚有积分，暂时不能注销。',		
						buttonText: '确定',
						confirmText: "确定",
					    success: function (res) {
					        if (res.confirm) {
					            console.log('用户点击确定');
								// that.addcompany();//去认证公司
								that.visible=false;
					        } else if (res.cancel) {
					            console.log('用户点击取消');
					        }
					    }
					});
					return;
			}
			
			uni.showModal({
			    title: '',
			    content: '请确定是否需要注销公司资料？',						
				
				buttonText: '确定',
				confirmText: "确定",
			    success: function (res) {
			        if (res.confirm) {
			            console.log('用户点击确定');
						// that.addcompany();//去认证公司
						that.visible=true
			        } else if (res.cancel) {
			            console.log('用户点击取消');
			        }
			    }
			});
		},
		gochangegongshi(){
			uni.showToast({
			    icon: 'none',
			    title: '功能未开放.',
			    duration: 2000
			});
			return
			console.log(this.userForm)
			let tmpuserinfo = JSON.stringify(this.userForm)
			uni.navigateTo({
			    url: '../shouquan/shouji?tmpuinfo='+tmpuserinfo+'&type=chphone'
			});
			
		},
		
		/*更换手机号码*/
		gochangephone(){
			console.log(this.userForm)
			let tmpuserinfo = JSON.stringify(this.userForm)

			uni.navigateTo({
			    url: '../shouquan/shouji?tmpuinfo='+tmpuserinfo+'&type=chphone'
			});
		},
		
		submit() {
			console.log(this.userForm)
			if(!check(this.userForm.mobile,'phoneno')){
				 return
			}
			if(!check(this.userForm.identitycard,'shengfen')){
				 return
			}
			 
			this.userForm.type = 'edit'
			if(this.sexindex == 0){
				this.userForm.sex = 2
				}else{
					this.userForm.sex = 1
				}
			
			useredit(this.userForm).then(res=>{
				if(res.data.code === 200){
					uni.showToast({
					    icon: 'none',
					    title: '修改成功',
					    duration: 2000
					});
					this.chooseinput=true;
				}else{
					uni.showToast({
					    icon: 'none',
					    title: '网络繁忙,请稍后再试',
					    duration: 2000
					});
					
				}

			})
		}
	},
	onLoad() {
		userinfo({}).then(res=>{
			console.log(res)
			 this.userForm=res.data.data;
			 this.userFormnew=res.data;
			 var companyid=res.data.data.companyid;
			if(companyid){
				companyinfo({id:companyid}).then(res=>{
					this.companyinfodata=res.data.data
				})
				
			}
			if(this.userForm.is_completeperson=='2'&&this.userForm.roleid=='2'){
				this.is_completepersonchanger =  true;
			}
			
			// this.userForm.sex=sexl;	
			// if(sexl==1){
			// 	this.sexindex = 1
			// 	this.userForm.sex='男';	
			// }else{
			// 	this.sexindex = 0
			// 	this.userForm.sex='女';
			// }
			
		})
	},
	filters:{
		sexfiter(value){
			
		}
	},
			
};
</script>

<style>
.user-imgshow image{width: 160upx;}
.user-message {
	padding: 5px 10px;
	color: rgba(80, 80, 80, 1);
	font-size: 15px;
	border-bottom: 1px solid #ccc;
	display: flex;
	align-items: center;
	width: 90%;
	margin: 0 auto;
}
.user-message2 {
	padding: 5px 10px;
	color: rgba(80, 80, 80, 1);
	font-size: 15px;
	border-bottom: 1px solid #ccc;
	width: 90%;
	margin: 0 auto;
}
.submit {
	width: 192px;
	height: 42px;

	color: rgba(255, 255, 255, 1);
	background-color: rgba(212, 48, 48, 1);
	border-radius: 8px;
	font-size: 15px;
	line-height: 42px;
	text-align: center;
	margin: auto;
	margin-top: 50px;
}
.bglin{
	background-color: #007aff;
	margin-left: 5px;
}
.bglin2{
	background-color: rgba(212, 48, 48, 1);
	margin-left: 5px;
}
.submitsm{width: 130px;}
.uni-btn-v{display: flex;}
.scan-box{
		display:block;
		position:fixed;
		top:0;
		bottom:0;
		left:0;
		right:0;
		background-color:rgba(0, 0, 0, 0.3);
		z-index:991;
	}
	.scan-item{
		display:-webkit-box;
		display:-webkit-flex;
		display:-ms-flexbox;
		display:flex;
		position:relative;
		margin:0 auto;
		width:80%;
		height:100%;
		-webkit-box-pack:center;
		-webkit-justify-content:center;
		-ms-flex-pack:center;
		justify-content:center;
		-webkit-box-align:center;
		-webkit-align-items:center;
		-ms-flex-align:center;
		align-items:center;
		-webkit-box-sizing:border-box;
		box-sizing:border-box;
		opacity:1;

	}
	.scan-content{
		position:relative;
		width: 460upx;
		height: 310upx;
		background: #FFFFFF;
		border-radius: 20upx;
	}
	
	.scan-text{
		position: absolute;
		bottom: 40upx;
		left: 0;
		width: 100%;
		text-align: center;
		font-size: 14px;
	}
	.scan-share{
		width: 100%;
		height: 100%;
	}
	.scan-img{
		width: 300upx;
		height: 300upx;
		margin: auto;
		display: block;
		position: absolute;
		top: 60upx;
		left: 50upx;
		z-index: 99;
	}
	.scan-btn{
		top:-30upx;
		left:auto;
		right:-30upx;
		bottom:auto;
		position:absolute;
		width:64upx;
		height:64upx;
		border-radius:50%;
		z-index:99999;
		display: flex;
	}
</style>